package com.atguigu.gmall.list.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.list.service.GoodsService;
import com.atguigu.gmall.list.service.SearchService;
import com.atguigu.gmall.model.list.SearchParam;
import com.atguigu.gmall.model.list.SearchResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "商品")
@RestController
@RequestMapping("/api/list")
public class ApiListController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private SearchService searchService;

    @ApiOperation("查询商品装入es")
    @GetMapping("/inner/do/es/goods//{skuId}")
    public Result doESGoodsSave(@PathVariable("skuId") Long skuId) {
        goodsService.saveGoods(skuId);
        return Result.ok();
    }

    @ApiOperation("商品删除")
    @DeleteMapping("/remove/goods/from/elastic/search/{skuId}")
    public Result doESGoodsRemove(@PathVariable("skuId") Long skuId) {
        goodsService.removeGoods(skuId);
        return Result.ok();
    }

    @ApiOperation("商品热点")
    @GetMapping("/inner/incr/goods/hot/score/{skuId}")
    public Result<Void> incrGoodsHotScore(@PathVariable("skuId") Long skuId) {
        goodsService.incrGoodsHotScore(skuId);
        return Result.ok();
    }

    @PostMapping("/do/search")
    public Result<SearchResponseVo> doSearch(@RequestBody SearchParam searchParam) {
        SearchResponseVo searchResponseVo = searchService.doSearch(searchParam);
        return Result.ok(searchResponseVo);
    }
}
